﻿@using Fzrain.Web.Models.Scheduler

@{
    ViewBag.Title = "Index";
    Layout = "~/Views/Shared/_Layout.cshtml";
}


<div id="team-schedule" style="display :none ">
    <div id="people">
        <input checked type="checkbox" id="alex" value="1">
        <input checked type="checkbox" id="bob" value="2">
        <input type="checkbox" id="charlie" value="3">
    </div>
</div>
@(Html.Kendo().Scheduler<SchedulerViewModel>()
    .Name("scheduler")
    .Date(DateTime.Now)
    .StartTime(new DateTime(2013, 6, 13, 7, 00, 00))
    .Height(600)
    .Views(views =>
    {
        views.DayView();
        views.WorkWeekView(workWeekView => workWeekView.Selected(true));
        views.WeekView();
        views.MonthView();
        views.AgendaView();
     
    })
    .Timezone("Etc/UTC")
    .Resources(resource => resource.Add(m => m.SchedulerType)
        .Title("所有者")
        .DataTextField("Text")
        .DataValueField("Value")
        .DataColorField("Color")
        .BindTo(new[] {
            new { Text = "Alex", Value = 1, Color = "#f8a398" } ,
            new { Text = "Bob", Value = 2, Color = "#51a0ed" } ,
            new { Text = "Charlie", Value = 3, Color = "#56ca85" }
        }))
    .DataSource(d => d
        .Model(m =>
        {
            m.Id(f => f.SchedulerID);
            m.Field(f => f.Title).DefaultValue("No title");
            m.Field(f => f.SchedulerType).DefaultValue(1);
            m.RecurrenceId(f => f.RecurrenceID);
        })
        .Read("Read", "Scheduler")
        .Create("Create", "Scheduler")
        .Destroy("Destroy", "Scheduler")
        .Update("Update", "Scheduler")
        .Filter(filters => filters.Add(model => model.SchedulerType).IsEqualTo(1).Or().IsEqualTo(2))
    )
)

<script type="text/javascript">
    $(function () {
        $("#people :checkbox").change(function (e) {
            var checked = $.map($("#people :checked"), function (checkbox) {
                return parseInt($(checkbox).val());
            });

            var filter = {
                logic: "or",
                filters: $.map(checked, function (value) {
                    return {
                        operator: "eq",
                        field: "OwnerID",
                        value: value
                    };
                })
            };

            var scheduler = $("#scheduler").data("kendoScheduler");

            scheduler.dataSource.filter(filter);
        });
    })
</script>

